<template>
  <div id="data-box">
    <div class="data-div1">
      <el-table
          :data="tableData"
          style="width: 100%"
          :row-class-name="tableRowClassName">
        <el-table-column
            prop="img"
            width="40"
            label="">
          <template slot-scope="scope">
            <img :src="scope.row.img" :min-width="30" :height="30"/>
          </template>
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="site"
            label="姓名">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="region"
            label="所属区域">
        </el-table-column>
        <el-table-column
            prop="houseType"
            label="房源类型">
        </el-table-column>
        <el-table-column
            prop="price"
            label="价格">
        </el-table-column>
        <el-table-column
            prop="houseM"
            label="户型">
        </el-table-column>
        <el-table-column
            prop="rentType"
            label="出租类型">
        </el-table-column>
        <el-table-column
            show-overflow-tooltip
            prop="bedType"
            label="床型">
        </el-table-column>
        <el-table-column
            prop="bedCount"
            label="总床数">
        </el-table-column>
        <el-table-column
            prop="personCount"
            label="可住人数">
        </el-table-column>
        <el-table-column
            prop="toiletCount"
            label="独立卫生间数">
        </el-table-column>
        <el-table-column
            prop="houseS"
            label="房屋面积">
        </el-table-column>
        <el-table-column
            prop="invoice"
            label="发票">
        </el-table-column>
        <el-table-column
            prop="score"
            label="综合评分">
        </el-table-column>
        <el-table-column
            prop="city"
            label="城市">
        </el-table-column>
      </el-table>
    </div>
    <div class="data-div2" v-show="tableData.length > 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage1"
          :page-sizes="[11, 22, 44, 88]"
          :page-size="100"
          layout="total, sizes, prev, pager, next, jumper"
          :total=pageCount>
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DataManagement',
  data() {
    return {
      pageSize: 11,
      pageCount: 0,
      currentPage1: 1,
      tableData: []
    }
  },
  mounted() {
    this.getPageCount();
    this.getDataAll(0, this.pageSize);
  },
  methods: {
    open1(msg) {
      this.$notify({
        title: msg,
        message: '这是一条成功的提示消息',
        type: 'success'
      });
    },
    open2(msg) {
      this.$notify({
        title: msg,
        message: '这是一条警告的提示消息',
        type: 'warning'
      });
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    tableRowClassName({row, rowIndex}) {
      if (rowIndex === 1) {
        return 'warning-row' + row;
      } else if (rowIndex === 3) {
        return 'success-row';
      }
      return '';
    },
    //  分页
    handleSizeChange(val) {
      this.pageSize = val;   // 没有分页数
    },
    handleCurrentChange(val) {
      this.tableData = [];
      let start = (val - 1) * this.pageSize;
      this.getDataAll(start, this.pageSize)

    },
    getPageCount() {
      this.$axios.get('/api/dataNum', {}).then(res => {
        if (res.data.code === 200) {
          this.pageCount = res.data.result.data;
        }
      }).catch(error => {
        this.open4(error);
      })
    },
    getDataAll(start, end) {
      this.$axios.post('/api/datainfo', {
        "start": start,
        "end": end
      }).then(res => {
        if (res.data.code === 200) {
          this.tableData = [];
          for (let i = 0; i < res.data.result.length; i++) {
            this.tableData.push(
                {
                  img: res.data.result[i].Playerid,
                  site: res.data.result[i].displayName,
                }
            )

          }
        }
      }).catch(error => {
        this.open4(error);
      })
    }
  }
}
</script>

<style scoped>

#data-box {
  height: 100%;
  width: 100%;
  .el-table .warning-row {
    background: oldlace;
  }

  .el-table .success-row {
    background: #f0f9eb;
  }
  overflow-x: hidden;
  overflow-y: auto;
}
#data-box .data-div1 {
  top: 10%;
  width: 100%;
  margin: auto;
}
#data-box .data-div2 {
  width: 40%;
  margin: auto;
}

</style>